@@ -233,6 +233,7 @@ impl Primitive2d for Segment2d {}
233
233
234
234
impl Segment2d {
235
235
/// Create a new `Segment2d` from a direction and full length of the segment
236
+ #[ inline( always) ]
236
237
pub fn new ( direction : Direction2d , length : f32 ) -> Self {
237
238
Self {
238
239
direction,
@@ -245,6 +246,7 @@ impl Segment2d {
245
246
/// # Panics
246
247
///
247
248
/// Panics if `point1 == point2`
249
+ #[ inline( always) ]
248
250
pub fn from_points ( point1 : Vec2 , point2 : Vec2 ) -> ( Self , Vec2 ) {
249
251
let diff = point2 - point1;
250
252
let length = diff. length ( ) ;
@@ -257,11 +259,13 @@ impl Segment2d {
257
259
}
258
260
259
261
/// Get the position of the first point on the line segment
262
+ #[ inline( always) ]
260
263
pub fn point1 ( & self ) -> Vec2 {
261
264
* self . direction * -self . half_length
262
265
}
263
266
264
267
/// Get the position of the second point on the line segment
268
+ #[ inline( always) ]
265
269
pub fn point2 ( & self ) -> Vec2 {
266
270
* self . direction * self . half_length
267
271
}
@@ -332,19 +336,22 @@ impl Primitive2d for Triangle2d {}
332
336
333
337
impl Triangle2d {
334
338
/// Create a new `Triangle2d` from points `a`, `b`, and `c`
339
+ #[ inline( always) ]
335
340
pub fn new ( a : Vec2 , b : Vec2 , c : Vec2 ) -> Self {
336
341
Self {
337
342
vertices : [ a, b, c] ,
338
343
}
339
344
}
340
345
341
346
/// Get the area of the triangle
347
+ #[ inline( always) ]
342
348
pub fn area ( & self ) -> f32 {
343
349
let [ a, b, c] = self . vertices ;
344
350
( a. x * ( b. y - c. y ) + b. x * ( c. y - a. y ) + c. x * ( a. y - b. y ) ) . abs ( ) / 2.0
345
351
}
346
352
347
353
/// Get the perimeter of the triangle
354
+ #[ inline( always) ]
348
355
pub fn perimeter ( & self ) -> f32 {
349
356
let [ a, b, c] = self . vertices ;
350
357
@@ -356,6 +363,7 @@ impl Triangle2d {
356
363
}
357
364
358
365
/// Get the [`WindingOrder`] of the triangle
366
+ #[ inline( always) ]
359
367
#[ doc( alias = "orientation" ) ]
360
368
pub fn winding_order ( & self ) -> WindingOrder {
361
369
let [ a, b, c] = self . vertices ;
@@ -406,6 +414,7 @@ impl Triangle2d {
406
414
407
415
/// Reverse the [`WindingOrder`] of the triangle
408
416
/// by swapping the second and third vertices
417
+ #[ inline( always) ]
409
418
pub fn reverse ( & mut self ) {
410
419
self . vertices . swap ( 1 , 2 ) ;
411
420
}
@@ -421,35 +430,41 @@ pub struct Rectangle {
421
430
422
431
impl Rectangle {
423
432
/// Create a new `Rectangle` from a full width and height
433
+ #[ inline( always) ]
424
434
pub fn new ( width : f32 , height : f32 ) -> Self {
425
435
Self :: from_size ( Vec2 :: new ( width, height) )
426
436
}
427
437
428
438
/// Create a new `Rectangle` from a given full size
439
+ #[ inline( always) ]
429
440
pub fn from_size ( size : Vec2 ) -> Self {
430
441
Self {
431
442
half_size : size / 2.0 ,
432
443
}
433
444
}
434
445
435
446
/// Create a new `Rectangle` from two corner points
447
+ #[ inline( always) ]
436
448
pub fn from_corners ( point1 : Vec2 , point2 : Vec2 ) -> Self {
437
449
Self {
438
450
half_size : ( point2 - point1) . abs ( ) / 2.0 ,
439
451
}
440
452
}
441
453
442
454
/// Get the size of the rectangle
455
+ #[ inline( always) ]
443
456
pub fn size ( & self ) -> Vec2 {
444
457
2.0 * self . half_size
445
458
}
446
459
447
460
/// Get the area of the rectangle
461
+ #[ inline( always) ]
448
462
pub fn area ( & self ) -> f32 {
449
463
4.0 * self . half_size . x * self . half_size . y
450
464
}
451
465
452
466
/// Get the perimeter of the rectangle
467
+ #[ inline( always) ]
453
468
pub fn perimeter ( & self ) -> f32 {
454
469
4.0 * ( self . half_size . x + self . half_size . y )
455
470
}
@@ -537,6 +552,7 @@ impl RegularPolygon {
537
552
/// # Panics
538
553
///
539
554
/// Panics if `circumradius` is non-positive
555
+ #[ inline( always) ]
540
556
pub fn new ( circumradius : f32 , sides : usize ) -> Self {
541
557
assert ! ( circumradius > 0.0 , "polygon has a non-positive radius" ) ;
542
558
assert ! ( sides > 2 , "polygon has less than 3 sides" ) ;
@@ -551,31 +567,36 @@ impl RegularPolygon {
551
567
552
568
/// Get the radius of the circumcircle on which all vertices
553
569
/// of the regular polygon lie
570
+ #[ inline( always) ]
554
571
pub fn circumradius ( & self ) -> f32 {
555
572
self . circumcircle . radius
556
573
}
557
574
558
575
/// Get the inradius or apothem of the regular polygon.
559
576
/// This is the radius of the largest circle that can
560
577
/// be drawn within the polygon
578
+ #[ inline( always) ]
561
579
#[ doc( alias = "apothem" ) ]
562
580
pub fn inradius ( & self ) -> f32 {
563
581
self . circumradius ( ) * ( PI / self . sides as f32 ) . cos ( )
564
582
}
565
583
566
584
/// Get the length of one side of the regular polygon
585
+ #[ inline( always) ]
567
586
pub fn side_length ( & self ) -> f32 {
568
587
2.0 * self . circumradius ( ) * ( PI / self . sides as f32 ) . sin ( )
569
588
}
570
589
571
590
/// Get the area of the regular polygon
591
+ #[ inline( always) ]
572
592
pub fn area ( & self ) -> f32 {
573
593
let angle: f32 = 2.0 * PI / ( self . sides as f32 ) ;
574
594
( self . sides as f32 ) * self . circumradius ( ) . powi ( 2 ) * angle. sin ( ) / 2.0
575
595
}
576
596
577
597
/// Get the perimeter of the regular polygon.
578
598
/// This is the sum of its sides
599
+ #[ inline( always) ]
579
600
pub fn perimeter ( & self ) -> f32 {
580
601
self . sides as f32 * self . side_length ( )
581
602
}
@@ -584,6 +605,7 @@ impl RegularPolygon {
584
605
///
585
606
/// This is the angle formed by two adjacent sides with points
586
607
/// within the angle being in the interior of the polygon
608
+ #[ inline( always) ]
587
609
pub fn internal_angle_degrees ( & self ) -> f32 {
588
610
( self . sides - 2 ) as f32 / self . sides as f32 * 180.0
589
611
}
@@ -592,6 +614,7 @@ impl RegularPolygon {
592
614
///
593
615
/// This is the angle formed by two adjacent sides with points
594
616
/// within the angle being in the interior of the polygon
617
+ #[ inline( always) ]
595
618
pub fn internal_angle_radians ( & self ) -> f32 {
596
619
( self . sides - 2 ) as f32 * PI / self . sides as f32
597
620
}
@@ -600,6 +623,7 @@ impl RegularPolygon {
600
623
///
601
624
/// This is the angle formed by two adjacent sides with points
602
625
/// within the angle being in the exterior of the polygon
626
+ #[ inline( always) ]
603
627
pub fn external_angle_degrees ( & self ) -> f32 {
604
628
360.0 / self . sides as f32
605
629
}
@@ -608,6 +632,7 @@ impl RegularPolygon {
608
632
///
609
633
/// This is the angle formed by two adjacent sides with points
610
634
/// within the angle being in the exterior of the polygon
635
+ #[ inline( always) ]
611
636
pub fn external_angle_radians ( & self ) -> f32 {
612
637
2.0 * PI / self . sides as f32
613
638
}
0 commit comments