[squeak-dev] The Trunk: System-mt.1088.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Sep 2 07:12:33 UTC 2019


Marcel Taeumel uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-mt.1088.mcz

==================== Summary ====================

Name: System-mt.1088
Author: mt
Time: 2 September 2019, 9:12:20.976272 am
UUID: 3e565c44-884e-0d47-b919-b0071d31f64c
Ancestors: System-mt.1087

Moves utility method from MenuItemMorph.

We should think about having more geometry classes such as Triangle. See: http://forum.world.st/Proposal-Geometry-Classes-td5093998.html

=============== Diff against System-mt.1087 ===============

Item was added:
+ ----- Method: Utilities class>>triangle:containsPoint: (in category 'geometry testing') -----
+ triangle: points containsPoint: p
+ 	" Computes if p is in the triangle defined by points.
+ 	p should be a Point, and points should be an array with three Points.
+ 	I took the algorithm from the bottom of this page: 
+ 		http://www.blackpawn.com/texts/pointinpoly/default.html "
+ 
+ 	| a b c v0 v1 v2 dot00 dot01 dot02 dot11 dot12 denom invDenom u v |
+ 	a := points first.
+ 	b := points second.
+ 	c := points third.
+ 	" Compute vectors "
+ 	v0 := c - a.
+ 	v1 := b - a.
+ 	v2 := p - a.
+ 	" Compute dot products "
+ 	dot00 := v0 dotProduct: v0.
+ 	dot01 := v0 dotProduct: v1.
+ 	dot02 := v0 dotProduct: v2.
+ 	dot11 := v1 dotProduct: v1.
+ 	dot12 := v1 dotProduct: v2.
+ 	" Compute barycentric coordinates "
+ 	denom := dot00 * dot11 - (dot01 * dot01).
+ 	denom = 0 ifTrue: [ ^false ].
+ 	invDenom := 1 / denom.
+ 	u := (dot11 * dot02 - (dot01 * dot12)) * invDenom.
+ 	v := (dot00 * dot12 - (dot01 * dot02)) * invDenom.
+ 	" Check if point is in triangle "
+ 	^u >= 0 and: [ v >= 0 and: [ u + v <= 1 ] ]!



More information about the Squeak-dev mailing list